﻿using BitButterCORE.Component;
using BitButterCORE.Factory;

namespace BitButterCORE.Object
{
	public class ObjectReference<T> : IObjectReference<T>
		where T : BaseObject
	{
		public ObjectReference(IFactory factory, uint id)
		{
			Factory = factory;
			ID = id;
		}

		public virtual IFactory Factory { get; }
		public virtual uint ID { get; }

		public virtual T Object => Factory[ID] as T;

		public U GetComponent<U>()
			where U : BaseComponent
		{
			return Object?.GetComponent<U>();
		}
	}

	public class EmptyObjectReference : ObjectReference<BaseObject>
	{
		public EmptyObjectReference()
			: base(null, 0)
		{
		}

		public override IFactory Factory => null;

		public override uint ID => 0;

		public override BaseObject Object => null;
	}
}
